<?php

namespace App\Http\Controllers\Api;

use App\Http\Requests\Api\PasswordRequest;

class PasswordController extends Controller
{
    /**
     * 修改密码
     * @param PasswordRequest $request
     * @return mixed
     */
    public function update(PasswordRequest $request)
    {
        $oldPassword = $request->input('old_password', '');
        $password = $request->input('password', '');
        $user = $this->user();

        if (!password_verify($oldPassword, $user['password'])) {
            return $this->failed('旧密码输入不正确', 401);
        }
        $user->password = bcrypt($password);
        $user->save();

        return $this->success('密码修改成功');
    }
}
